﻿using ETC.DLEDLightingSystemPlus.Helpers;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ETC.DLEDLightingSystemPlus.Models
{
    public class Tetra : Bandit.UI.MVVM.NotifyObject
    {
        public const string DefaultAddress = "192.168.5.55";

        private string _Address;
        /// <summary>
        /// Address
        /// </summary>
        public string Address
        {
            get { return _Address; }
            set
            {
                _Address = value;
                OnPropertyChanged("Address");
            }
        }

        private bool _IsSelected = true;

        public bool IsSelected
        {
            get { return _IsSelected; }
            set
            {
                _IsSelected = value;
                OnPropertyChanged(nameof(IsSelected));
            }
        }

        private string _Name;
        /// <summary>
        /// Name
        /// </summary>
        public string Name
        {
            get { return _Name; }
            set
            {
                _Name = value;
                OnPropertyChanged("Name");
            }
        }

        private bool _State;
        /// <summary>
        /// State
        /// </summary>
        [JsonIgnore]
        public bool State
        {
            get { return _State; }
            set
            {
                _State = value;
                OnPropertyChanged("State");
            }
        }

        private string _Remark;
        /// <summary>
        /// Remark
        /// </summary>
        public string Remark
        {
            get { return _Remark; }
            set { _Remark = value; OnPropertyChanged("Remark"); }
        }

        private string _UserName = Guid.NewGuid().ToString();
        /// <summary>
        /// UserName
        /// </summary>
        //[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
        //[JsonConverter(typeof(EncryptConverter))]
        public string UserName
        {
            get { return _UserName; }
            set
            {
                _UserName = value;
                OnPropertyChanged("UserName");
            }
        }

        private string _Password = "Aa123456";
        /// <summary>
        /// Password
        /// </summary>
        [JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
        [JsonConverter(typeof(EncryptConverter))]
        public string Password
        {
            get { return _Password; }
            set
            {
                _Password = value;
                OnPropertyChanged("Password");
            }
        }

        public Tetra()
        {

        }
        public Tetra(string address, string name, string remark)
        {
            Address = address;

            Name = name;

            Remark = remark;

        }

        public override string ToString()
        {
            return string.Format("{0}{1}", this.Address, string.IsNullOrWhiteSpace(this.Name) ? "" : " [" + this.Name + "]");
        }
    }
}
